package com.xinhe.web.controller;

import com.querydsl.core.QueryResults;
import com.xinhe.web.annotation.WebUsed;
import com.xinhe.web.common.Result;
import com.xinhe.web.entity.AdoptedTree;
import com.xinhe.web.service.AdoptedTreeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;

@Api(value = "认养树", tags = {"认养树"})
@RestController
@RequestMapping(value = {"/adoptedTree"}, produces = {"application/json;charset=UTF-8"})

public class AdoptedTreeController {
    @Autowired
    private AdoptedTreeService adoptedTreeService;

    @WebUsed
    @ApiOperation(httpMethod = "GET", value = "分页查询认养树")
    @RequestMapping({"/pageAdoptedTree"})
    public QueryResults<AdoptedTree> pageAdoptedTree(int pageNum, int pageSize) {
        return adoptedTreeService.pageAdoptedTree(pageNum,pageSize);
    }
    @WebUsed
    @ApiOperation(httpMethod = "POST", value = "保存认养树")
    @RequestMapping({"/saveAdoptedTree"})
    public Result saveAdoptedTree(Long id, String name, String iconPath, Integer adoptedYear,
                                  BigDecimal yunChaSeed,BigDecimal teaOilCard,BigDecimal consumerGoldRedEnvelope,
                                  BigDecimal price,String remark) {
        return adoptedTreeService.saveModel(id,name,iconPath,adoptedYear,yunChaSeed,teaOilCard,consumerGoldRedEnvelope,price,remark);
    }

    @WebUsed
    @ApiOperation(httpMethod = "GET", value = "删除认养树")
    @ApiImplicitParam(name = "adoptedTreeId", value = "标识", dataTypeClass = Long.class, required = true)
    @RequestMapping({"/deleteAdoptedTree"})
    public Result deleteAdoptedTree(Long adoptedTreeId) {
        return adoptedTreeService.delete(adoptedTreeId);
    }


    @ApiOperation(httpMethod = "GET", value = "认养树详情")
    @RequestMapping({"/detailAdoptedTree"})
    public Result<AdoptedTree> detailAdoptedTree(Long adoptedTreeId, Integer num) {
        return adoptedTreeService.detailAdoptedTree(adoptedTreeId, num);
    }
    @WebUsed
    @ApiOperation(httpMethod = "GET", value = "认养树详情(管理平台)")
    @PostMapping({"/findByAdoptedTree"})
    public Result<AdoptedTree> findByAdoptedTree(Long adoptedTreeId) {
        return adoptedTreeService.findById(adoptedTreeId);
    }
}
